package org.javaboy.demo;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * public class CalculatorProxy implements ICalculator{
 *     ICalculatorImpl icalculatorImpl = new ICalculatorImpl();
 *     public int add(int a,int b){
 *         Object proceed;
 *         try {
 *             //这一句就相当于是前置通知了
 *             long startTime = System.currentTimeMillis();
 *             //这句话其实就是执行目标方法
 *             proceed = icalculatorImpl.add(a,b);
 *             //这里就是后置通知了
 *             long endTime = System.currentTimeMillis();
 *             System.out.println(pjp.getSignature().getName() + " 方法执行耗时 " + (endTime - startTime) + " 毫秒");
 *         } catch (Throwable e) {
 *             //这里就是异常通知
 *             //xxx
 *             throw new RuntimeException(e);
 *         }
 *         return proceed;
 *     }
 * }
 */
public class Demo01 {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
        ICalculator calculator = ctx.getBean(ICalculator.class);
        calculator.add(3, 4);
        calculator.minus(3, 4);
        //我们向 Spring 容器注册的 ICalculatorImpl，现在已经被自动代理了，所以 Spring 容器中现在是不存在 ICalculatorImpl
//        ICalculatorImpl calculator = ctx.getBean(ICalculatorImpl.class);
//        calculator.add(3, 4);
    }
}
